package com.hnhn.c69.boot.controller;

import com.hnhn.c69.boot.pojo.MedicalAssay;
import com.hnhn.c69.boot.service.MedicalAssayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class MedicalAssayController {
    @Autowired
    MedicalAssayService medicalAssayService;

    @RequestMapping("/list")
    public String list(Integer hospitalId, Model model){
        model.addAttribute("hospitalId",hospitalId);
        model.addAttribute("assays",medicalAssayService.findMed(hospitalId));
        return "list";
    }

    @RequestMapping("/update/{id}/{result}")
    @ResponseBody
    public Object result(@PathVariable Integer id,@PathVariable Integer result){
       int row= medicalAssayService.updateResult(id, result);
        Map<String,Boolean> map=new HashMap<>();
        if(row>0){
            map.put("flag",true);
        }else {
            map.put("flag",false);
        }
        return map;
    }

    @RequestMapping("/add")
    public Object result(MedicalAssay medicalAssay){
        int row= medicalAssayService.add(medicalAssay);
        if(row>0){
            return "redirect:/list";
        }else   {
            return "add";
        }
    }


}
